package com.hualan.sfzy.service.impl.permission;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hualan.sfzy.constant.CommonConstant;
import com.hualan.sfzy.mapper.permission.RoleMapper;
import com.hualan.sfzy.model.entity.Role;
import com.hualan.sfzy.service.BaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static net.sf.jsqlparser.util.validation.metadata.NamedObject.role;
@Service
public class RoleServiceImpl implements BaseService<Role> {
    @Autowired
    private RoleMapper roleMapper;

    @Override
    public int add(Role role) {
        return roleMapper.insert(role);
    }

    @Override
    public int edit(Role role) {
        return roleMapper.update(role);
    }

    @Override
    public int remove(Integer id) {
        return roleMapper.delete(id);
    }

    @Override
    public int removeBatch(Integer[] ids) {
        return roleMapper.deleteBatch(ids);
    }

    @Override
    public List<Role> find() {
        return roleMapper.select(null);
    }

    @Override
    public Map<String, Object> findPage(Integer pageNum, Integer pageSize, Role role) {
        PageHelper.startPage(pageNum, pageSize);
        List<Role> list = roleMapper.select(role);
        PageInfo<Role> pageInfo = new PageInfo<>(list);
        Map<String, Object> pageMap = new HashMap<>();
        pageMap.put(CommonConstant.PAGE_LIST,list);
        pageMap.put(CommonConstant.PAGE_TOTAL, pageInfo.getPages());
        pageMap.put(CommonConstant.TOTAL, pageInfo.getList());
        return pageMap;
    }

    @Override
    public Role findById(Integer id) {
        return roleMapper.selectById(id);
    }
}
